package com.daiyang.campus_lucky_draw.mapper;

import com.daiyang.campus_lucky_draw.mapper.DO.PrizeDO;
import jakarta.validation.constraints.NotNull;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PrizeMapper {
    @Insert("insert into prize (name, description, price, image_url)"
            + " values (#{name}, #{description}, #{price}, #{imageUrl})")
    @Options(useGeneratedKeys=true, keyProperty="id", keyColumn="id")
    int insert(PrizeDO prizeDO);

    @Select("select count(1) from prize")
    int count();

    /**
     * 翻⻚查询
     *
     * @param offset
     * @param pageSize
     * @return
     */
    @Select("select * from prize order by id desc limit #{offset}, #{pageSize}")
    List<PrizeDO> queryPrizesByPage(@Param("offset") Integer offset,
                                    @Param("pageSize") Integer pageSize);

    @Select("<script>" +
            " select id from prize" +
            " where id in" +
            " <foreach item='item' collection='items' open='(' separator=',' close=')'>" +
            " #{item}" +
            " </foreach>" +
            " </script>")
    List<Long> selectExistByIds(@Param("items") List<Long> ids);
    @Select("<script>" +
            " select * from prize" +
            " where id in" +
            " <foreach item='item' collection='items' open='(' separator=',' close=')'>" +
            " #{item}" +
            " </foreach>" +
            " </script>")
    List<PrizeDO> selectByIdList(@Param("items") List<Long> prizeIds);

    @Select("<script>"+
            " select * from prize " +
            " where id in " +
            " <foreach  item='item'  collection='prizeIds' open='(' separator=',' close=')'>" +
            " #{item}" +
            " </foreach> " +
            "</script>")
    List<PrizeDO> batchSelectByIds(@Param("prizeIds") List<Long> prizeIds);

    @Select("select * from prize where id = #{prizeId}")
    PrizeDO selecrtById(@NotNull(message = "奖品id不能为空")Long prizeId);
}